package com.ruoyi.system.controller;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.dto.ShipmentOrderDetailDTO;
import com.ruoyi.system.vo.ShipmentOrderDetailVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ShipmentOrderDetail;
import com.ruoyi.system.service.IShipmentOrderDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库单详情Controller
 * 
 * @author ruoyi
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/wms/orderdetail")
public class ShipmentOrderDetailController extends BaseController
{
    @Autowired
    private IShipmentOrderDetailService shipmentOrderDetailService;

    /**
     * 查询出库单详情列表
     */
    @PreAuthorize("@ss.hasPermi('wms:orderdetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShipmentOrderDetail shipmentOrderDetail)
    {
        startPage();
        List<ShipmentOrderDetailDTO> list = shipmentOrderDetailService.selectShipmentOrderDetailList(shipmentOrderDetail);
        return getDataTable(list);
    }

    /**
     * 查询出库单详情列表
     */
    @PreAuthorize("@ss.hasPermi('wms:orderdetail:list')")
    @GetMapping("/orderList")
    public TableDataInfo orderList(ShipmentOrderDetail shipmentOrderDetail)
    {
        startPage();
        List<Map<String, Object>> list = shipmentOrderDetailService.selectShipmentOrderList(shipmentOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出出库单详情列表
     */
    @PreAuthorize("@ss.hasPermi('wms:orderdetail:export')")
    @Log(title = "出库单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShipmentOrderDetail shipmentOrderDetail)
    {
        List<ShipmentOrderDetailDTO> list = shipmentOrderDetailService.selectShipmentOrderDetailList(shipmentOrderDetail);
        ExcelUtil<ShipmentOrderDetailDTO> util = new ExcelUtil<ShipmentOrderDetailDTO>(ShipmentOrderDetailDTO.class);
        util.exportExcel(response, list, "出库单详情数据");
    }

    /**
     * 获取出库单详情详细信息
     */
//    @PreAuthorize("@ss.hasPermi('wms:orderdetail:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return success(shipmentOrderDetailService.selectShipmentOrderDetailById(id));
//    }

    /**
     * 新增出库单详情
     */
    @PreAuthorize("@ss.hasPermi('wms:orderdetail:add')")
    @Log(title = "出库单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShipmentOrderDetail shipmentOrderDetail)
    {
        return toAjax(shipmentOrderDetailService.insertShipmentOrderDetail(shipmentOrderDetail));
    }

    /**
     * 修改出库单状态
     */
    @PreAuthorize("@ss.hasPermi('wms:orderdetail:edit')")
    @Log(title = "出库单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShipmentOrderDetailVO shipmentOrderDetail) throws SQLException {
        return shipmentOrderDetailService.updateShipmentOrderDetailState(shipmentOrderDetail);
    }


    /**
     * 删除出库单详情
     */
    @PreAuthorize("@ss.hasPermi('wms:orderdetail:remove')")
    @Log(title = "出库单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shipmentOrderDetailService.deleteShipmentOrderDetailByIds(ids));
    }
    /**
     * 看板数据统计查询
     */
    @PreAuthorize("@ss.hasPermi('wms:orderdetail:query')")
    @GetMapping(value = "/s/{status}")
    public AjaxResult selectStatusChuku(@PathVariable("status") int status)
    {
        return success(shipmentOrderDetailService.selectStatussChuku(status));
    }
}
